package ***;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.graphics.drawable.shapes.Shape;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;



import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by user on 2016/6/21.
 */
public class SplashActivity extends Activity implements View.OnClickListener {
    private ViewPager viewPager;

    private ProgressIndicator indicator;

    private List<Integer> resList = Arrays.asList(R.mipmap.splash1, R.mipmap.splash2, R.mipmap.splash3, R.mipmap.splash4);
  

    private List<View> list = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        viewPager = (ViewPager) findViewById(R.id.viewpager1);
        indicator = (ProgressIndicator) findViewById(R.id.progressIndicator1);

        indicator.setThumpDrawable(new CircleColorDrawable(colors.get(0)));

        boolean firstStart = Preferences.getBoolean("first_start", true);
        if (!firstStart) {
            return;
        }
        Preferences.put("first_start", false);
        for (int i = 0; i < resList.size(); i++) {
            View view = View.inflate(SplashActivity.this, R.layout.item_splah_page, null);
            ImageView imageView = new ImageView(this);
            imageView.setImageResource(resList.get(i));
           
            list.add(view);
        }

        viewPager.setAdapter(new PagerAdapter() {

            @Override
            public int getCount() {
                return resList.size();
            }

            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view == object;
            }

            @Override
            public Object instantiateItem(ViewGroup container, int position) {

                View child = list.get(position);
                container.addView(child, -1, -1);
                return child;
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                container.removeView(list.get(position));
            }
        });

        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                indicator.setProgress(position, true);
            }

            @Override
            public void onPageScrollStateChanged(int state) {
                
            }
        });
       
    }

  
}
